from datetime import datetime
from django.db import models

#POSICAO_D = ('0 - Posicao 1', '1 - Posicao 2', '2 - Posicao 3', '3 - Posicao 4')
CATEGORIA_CHOICE = (('0',' Shows'), ('1 ',' Congressos'), ('2 ',' Pecas'), ('3 ',' Festas'))

class Secao(models.Model):
    nome = models.CharField(max_length=100)
    descricao = models.TextField()
    slug = models.SlugField()
    data = models.DateTimeField(default=datetime.now)
    
    def __unicode__(self):
        return self.nome

class Autor(models.Model):
    nome = models.CharField(max_length=100)
    email = models.CharField(max_length=100)
    telefone = models.CharField(max_length=10)
    plus = models.URLField()

    def __unicode__(self):
        return self.nome

class Galeria (models.Model):
    nome = models.CharField(max_length=100)
    imagem = models.ImageField(upload_to='media/imagem/galeria',blank=True, null=True)
    data = models.DateTimeField(default=datetime.now)

    def __unicode__(self):
        return self.nome

class Noticia(models.Model):
    publicar = models.BooleanField(default=True)
    titulo = models.CharField(max_length=100)
    subtitulo = models.CharField(max_length=200)
    conteudo = models.TextField()
    autor = models.ForeignKey(Autor)
    fonte = models.CharField(max_length=50, blank=True, null=True)
    imagemdestaque = models.ImageField(upload_to='media/imagem/noticia')
    #posicaodestaque = models.CharField(CHOICES=POSICAO_D)
    secao = models.ForeignKey(Secao)
    dataentrada = models.DateTimeField(default=datetime.now,blank=True)
    video = models.URLField(blank=True, null=True)
    galeria = models.ManyToManyField(Galeria, blank=True, null=True)
    slug = models.SlugField()

    def __unicode__(self):
        return self.titulo

class Evento (models.Model):
    categoria = models.CharField(max_length=2, choices=CATEGORIA_CHOICE)
    nome = models.CharField(max_length=100)
    data = models.DateField(default=datetime.now)
    local = models.CharField(max_length=100)
    cidade = models.CharField(max_length=50)
    descricao = models.TextField()
    organizacao = models.CharField(max_length=100)
    slug = models.SlugField()

    def __unicode__(self):
        return self.nome

#SIGNALS
from django.db.models import signals
from django.template.defaultfilters import slugify

def noticia_pre_save(signal, instance, sender, **kwargs):
    instance.slug = slugify(instance.titulo)

signals.pre_save.connect(noticia_pre_save, sender=Noticia)

def secao_pre_save(signal, instance, sender, **kwargs):
    instance.slug = slugify(instance.nome)

signals.pre_save.connect(secao_pre_save, sender=Secao)

def evento_pre_save(signal, instance, sender, **kwargs):
    instance.slug = slugify(instance.nome)

signals.pre_save.connect(evento_pre_save, sender=Evento)
